package com_.dxy_test_.testjackson;

import cn.hutool.core.map.MapUtil;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Map;

/**
 * @Description TODO
 * @Author dangxianyue
 * @Date 2024/7/1 14:52
 */
@AllArgsConstructor
public class User {
    @Getter
    private Integer id;
    @Getter
    private String name;

    // 在序列化为json时添加额外的字段
    // 要求：1、方法为public 2、不能有参数 3、返回类型必须为Map<String, Object>
    @JsonAnyGetter
    public Map<String, Object> addProps() {
        Map<String, Object> dynamicProps = MapUtil.newHashMap();
        dynamicProps.put("age", 10);
        dynamicProps.put("email", "dxy1306@163.com");
        return dynamicProps;
    }

}
